import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

import { getDictTypeListApi } from '/@/api/admin/dict';
import { DICT } from '/@/enums/dict';
import { h } from 'vue';

export const columns: BasicColumn[] = [
  {
    title: '用户账号',
    dataIndex: 'postName',
    width: 140,
  },
  {
    title: '日志类型',
    dataIndex: 'deptName',
    width: 140,
  },
  {
    title: '操作时间',
    dataIndex: 'time',
    width: 140,
  },
  {
    title: 'URL地址',
    dataIndex: 'url',
    width: 250,
  },
  {
    title: '接口描述',
    dataIndex: 'des',
    width: 180,
  },
  {
    title: '登录IP地址',
    dataIndex: 'ip',
    width: 180,
  },
  {
    title: '登录结果',
    dataIndex: 'result',
    width: 180,
    customRender: ({ record }) => {
      return h('div', { style: { display: 'flex', alignItems: 'center' } }, [
        h('div', {
          style: {
            width: '6px',
            height: '6px',
            backgroundColor: '#4DB803',
            borderRadius: '50%',
            marginRight: '8px',
          },
        }),
        h('div', record.result),
      ]);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'postName',
    label: '用户账号',
    component: 'Input',
    colProps: { span: 5 },
    componentProps: {
      placeholder: '请输入用户账号',
    },
  },
  {
    field: 'deptName',
    label: '日志类型',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      placeholder: '请选择日志类型',
    },
  },
  {
    field: 'dateTime',
    label: '操作时间',
    component: 'RangePicker',
    colProps: { span: 5 },
    componentProps: {
      placeholder: ['开始日期', '结束日期'],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'postName',
    label: '岗位名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'postCode',
    label: '岗位编码',
    required: true,
    component: 'Input',
  },
  {
    field: 'postLevel',
    label: '岗位级别',
    component: 'ApiSelect',
    componentProps: {
      allowClear: false,
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.POST_LEVEL,
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    label: '排序',
    field: 'postSort',
    component: 'InputNumber',
  },
  {
    label: '岗位描述',
    field: 'remark',
    component: 'InputTextArea',
  },
];
